<?php

namespace App\Admin\Controllers;

use App\Models\Stock;
use App\Models\Suggestion;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class SuggestionController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '投诉管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Suggestion());

        $grid->column('id', __('Id'));
        $grid->column('user.username', __('用户名'));
        $grid->column('content', __('内容'));

        $grid->column('status', __('状态'))->display(function ($status) {
            return config('conf.suggestion_status')[$status];
        });
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('修改时间'));
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
//    protected function detail($id)
//    {
//        $show = new Show(Stock::findOrFail($id));
//
//        $show->field('id', __('Id'));
//        $show->field('code', __('产品code'));
//        $show->field('name', __('产品名称'));
//        $show->field('price', __('当前价格'));
//        $show->field('rebate', __('返利'));
//        $show->field('rebate_cycle', __('返利周期(单位小时)'));
//        $show->field('rebate_type', __('返利类型'));
//        $show->field('created_at', __('Created at'));
//        $show->field('updated_at', __('Updated at'));
//        $show->field('on_sale', __('状态'));
//
//        return $show;
//    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Suggestion());
        $form->text('user_id', __('用户'));
        $form->text('content', __('内容'));
        $form->select('status', __('状态'))->options(config('conf.suggestion_status'));

        return $form;
    }
}
